install.packages(c('tsibble', 'tsibbledata', 'feasts'))
also installing the dependencies ‘numDeriv’, ‘distributional’, ‘progressr’, ‘warp’, ‘fabletools’, ‘slider’
There is a binary version available but the source version is later:
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/numDeriv_2016.8-1.1.tgz'
Content type 'application/x-gzip' length 113250 bytes (110 KB)
==================================================
downloaded 110 KB
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/distributional_0.3.0.tgz'
Content type 'application/x-gzip' length 533681 bytes (521 KB)
==================================================
downloaded 521 KB
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/progressr_0.10.1.tgz'
Content type 'application/x-gzip' length 265811 bytes (259 KB)
==================================================
downloaded 259 KB
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/warp_0.2.0.tgz'
Content type 'application/x-gzip' length 103499 bytes (101 KB)
==================================================
downloaded 101 KB
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/fabletools_0.3.2.tgz'
Content type 'application/x-gzip' length 655065 bytes (639 KB)
==================================================
downloaded 639 KB
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/slider_0.2.2.tgz'
Content type 'application/x-gzip' length 360768 bytes (352 KB)
==================================================
downloaded 352 KB
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/tsibbledata_0.4.0.tgz'
Content type 'application/x-gzip' length 2173335 bytes (2.1 MB)
==================================================
downloaded 2.1 MB
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/feasts_0.2.2.tgz'
Content type 'application/x-gzip' length 1252288 bytes (1.2 MB)
==================================================
downloaded 1.2 MB
The downloaded binary packages are in
/var/folders/h4/vy1nwyvd5kz_n6950nl29pj80000gn/T//RtmpInwGKv/downloaded_packages
installing the source package ‘tsibble’
trying URL 'https://cran.rstudio.com/src/contrib/tsibble_1.1.2.tar.gz'
Content type 'application/x-gzip' length 1520385 bytes (1.4 MB)
==================================================
downloaded 1.4 MB
* installing *source* package ‘tsibble’ ...
** package ‘tsibble’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (tsibble)
The downloaded source packages are in
‘/private/var/folders/h4/vy1nwyvd5kz_n6950nl29pj80000gn/T/RtmpInwGKv/downloaded_packages’
library(tsibble)
Attaching package: ‘tsibble’
The following objects are masked from ‘package:base’:
intersect, setdiff, union
library(tsibbledata)
##tsibble
index : time component key: identifies the underlying structure of the data : in concojunction with the index uniquelu identifies each individual row
index_var(vic_elec)
[1] "Time"
interval(vic_elec)
<interval[1]>
[1] 30m
vic_elec %>%
filter(Time < as.POSIXct('2012-01-01 01:00:00', tz = 'Australia/Melbourne'))
vic_elec <- vic_elec %>%
mutate(year = lubridate::year(Date))
vic_elec
vic_elec %>%
select(year, Temperature) %>%
index_by(year) %>%
summarise(mean_temp = mean(Temperature))
vic_elec %>%
filter(!Holiday) %>%
ggplot()+
geom_line(aes(x=Time, y = Temperature))
elec_date <- vic_elec %>%
index_by(date = as_date(Time)) %>%
summarise(temp_mean = mean(Temperature, na.rm = TRUE))
elec_date
floor_date()
ceiling_date()
yearweek()
yearquarter()
elec_date %>%
ggplot(aes(date, temp_mean))+
geom_line()
NA
elec_m <- vic_elec %>%
index_by(month = month(Time, label = TRUE)) %>%
summarise(temp_mean = mean(Temperature, na.rm = TRUE))
elec_m
elec_m %>%
ggplot(aes(month, temp_mean))+
geom_point()+
geom_line(group = 1)
elec_year <- vic_elec %>%
index_by(year = year(Time)) %>%
summarise(temp_mean = mean(Temperature, na.rm = TRUE))
elec_year %>%
ggplot(aes(x = year, y = temp_mean)) +
geom_col(fill = "steelblue", alpha = 0.7) +
ylab("Mean Temperature")+
xlab("year")
library(slider)
elec_rolling <- vic_elec %>%
mutate(
temp_moving_avg = slide_dbl(
.x = Temperature,
.f = ~ mean(., na.rm = TRUE),
.before = 1000,
.after = 1000
)
)
elec_rolling
ggplot(elec_rolling) +
geom_line(aes(x = Date, y = Temperature), colour = "grey") +
geom_line(aes(x = Date, y = temp_moving_avg), colour = "red")
elec_rolling2 <- vic_elec %>%
mutate(
temp_moving_avg = slide_dbl(
.x = Temperature,
.f = ~ mean(., na.rm = TRUE),
.before = 100,
.after = 100,
.complete = TRUE
)
)
elec_rolling2
ggplot(elec_rolling2) +
geom_line(aes(x = Date, y = Temperature), colour = "grey") +
geom_line(aes(x = Date, y = temp_moving_avg), colour = "red")
#feasts
key_vars(tourism)
[1] "Region" "State" "Purpose"
holidays <- tourism %>%
filter(Purpose %in% c('Holiday', 'business')) %>%
group_by(State) %>%
summarise(Trips = sum(Trips))
holidays
holidays %>%
autoplot(Trips)+
xlab('Year')
holidays %>%
filter(State %in% c("Queensland", "New South Wales", "Victoria")) %>%
gg_season(Trips)
holidays %>%
filter(State %in% c("Queensland", "New South Wales", "Victoria")) %>%
gg_subseries(Trips)